package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.platform.service.OwnerService;
import com.ssps.entity.Owner;
import com.ssps.utils.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/24 14:17:28
 */

@Controller
@RequestMapping("owner")
public class OwnerController {

    @Autowired
    OwnerService ownerService;

    @RequestMapping("ownerList")
    public String ownerList(){
        return "/owner/ownerList";
    }

    @MyLog
    @ResponseBody
    @RequestMapping("findAll")
    public Map<String,Object> ownerFindAll(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize ,String status,String uname){
        Map<String,Object> map=new HashMap<>();
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Owner>ownerList=ownerService.ownerFindAll(status, uname);
            PageInfo<Owner>pageInfo=new PageInfo<>(ownerList);
            map.put("pageInfo",pageInfo);
            map.put("ownerList",ownerList);
            map.put("result",true);
        } catch (Exception e) {
            map.put("result",false);
            e.printStackTrace();
        }
        return map;

    }

    @MyLog()
    @ResponseBody
    @RequestMapping("updateAudit")
    public Map<String,Object> ownerUpdate(Owner owner){
        Map<String,Object> map=new HashMap<>();
        try {
            ownerService.ownerUpdate(owner);
            map.put("restult",true);
        } catch (Exception e) {
            map.put("restult",false);
            e.printStackTrace();
        }
        return map;
    }




}
